angular.module('service.fileupload', ['ngResource'])
        //this.uploadFileToUrl = function (file) {
        //    var fd = new FormData();
        //    fd.append('file', file);
        //    fd.append('sizelist', "100,200,400,500,800");
        //    var deferred = $q.defer();
        //    $http({
        //        method: "POST",
        //        url: uploadUrl,
        //        data: fd,
        //        headers: {'Content-Type': undefined},
        //        transformRequest: angular.identity
        //    }).success(function (data, status, headers, config) {
        //        deferred.resolve(data);
        //    }).error(function (data, status, headers, config) {
        //        deferred.reject(data);
        //    });
        //    return deferred.promise;
        //};
        .service('FileUpload', ['$q', '$resource','Upload','$http', function ( $q, $resource,Upload,$http) {
        this.uploadFileToUrl = function (file,progress) {
            var fd = new FormData();
            //fd.append('file', file);
            //fd.append("sizelist","100,200");
            var deferred = $q.defer();
            Upload.upload({
                method: "POST",
                url: uploadUrl,
                data: {"sizelist":"100,200"},
                file:file,
                headers: {'Content-Type': undefined},
                transformRequest: angular.identity
            }).progress(function (evt) {
                //progress(evt);
            }).success(function (data, status, headers, config) {
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                deferred.reject(data);
            });
            return deferred.promise;
        };


        //    this.uploadFileToUrl = function (file,progress) {
        //        var fd = new FormData();
        //        //fd.append('file', file);
        //        //fd.append("sizelist","100,200");
        //        var deferred = $q.defer();
        //        Upload.upload({
        //            method: "POST",
        //            url: uploadUrl,
        //            data: {"sizelist":"100,200"},
        //            file:file,
        //            headers: {'Content-Type': undefined},
        //            transformRequest: angular.identity
        //        }).progress(function (evt) {
        //            //progress(evt);
        //        }).success(function (data, status, headers, config) {
        //            deferred.resolve(data);
        //        }).error(function (data, status, headers, config) {
        //            deferred.reject(data);
        //        });
        //        return deferred.promise;
        //    };
        //this.saveFileToUrl = function (data, success, error) {
        //    var resource = $resource(saveimgurl + 'save/byurl/:serverid');
        //    return resource.save(
        //        {
        //            serverid: data.serverid,
        //            url: data.url,
        //            bizcode: data.bizcode,
        //            filename: data.filename,
        //            filetyppe: data.filetyppe,
        //            sizelist: data.sizelist,
        //        }, {}, success, error);
        //}
    }]);
